package com.leetcode.problems098;

import com.leetcode.util.TreeNode;

import java.util.*;

/**
 * 来源：力扣（LeetCode）
 * 链接：https://leetcode-cn.com/problems/validate-binary-search-tree/solution/
 * 著作权归领扣网络所有。商业转载请联系官方授权，非商业转载请注明出处。
 */
class Solution {

    public boolean isValidBST(TreeNode root) {
        List<Integer> ans = inOrderTreeNode(root);
        for (int i = 1; i < ans.size(); i++) {
            if(ans.get(i) <= ans.get(i - 1)){
                return false;
            }
        }
        return true;
    }

    public List<Integer> inOrderTreeNode(TreeNode root){
        List<Integer> ans = new ArrayList<>();
        TreeNode cur = root;
        Stack<TreeNode> stack = new Stack<>();
        while(cur != null || !stack.isEmpty()){
            while (cur != null){
                stack.push(cur);
                cur = cur.left;
            }
            cur = stack.pop();
            ans.add(cur.val);
            cur = cur.right;
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println();
    }
}